package com.fqy.servlet;

import com.fqy.dao.PeopleDaoImpl;
import com.fqy.dao.impl.PeopleDao;
import com.fqy.entity.People;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class UpdateServlet extends HttpServlet {
    public static int toInt(String strNum ){
        Integer integer = new Integer(strNum);
        return integer.parseInt(strNum);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PeopleDao peopleDao = new PeopleDaoImpl();
        int id = toInt(req.getParameter("id"));
        String name = req.getParameter("name");
        String sexuality = req.getParameter("sexuality");
        People people = new People(id, name, sexuality);
        System.out.println(id+name+sexuality);
        int i = peopleDao.updatePeople(people);
        resp.setCharacterEncoding("GBK");//编码方式
        PrintWriter out = resp.getWriter();
        if (i > 0) {
            out.println("修改成功");
        } else {
            out.println("修改失败");
        }
    }
}

